// pages/forget/forget.js
const app = getApp()
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    src: app.data.imgurl +"logo.png",
    username: app.data.imgurl +"username.png",
    password: app.data.imgurl +"password.png",
    code: app.data.imgurl +"code.png",
    nickname: app.data.imgurl +"nickname.png",
    loginbag: app.data.imgurl +"loginbg.png",
    phone:'',
    getcode: app.data.url + 'sheyingjia/myhuiyuan/getcode',
    chengepwd: app.data.url + 'sheyingjia/Xmyuser1/wchangepwd',
    text:'30s',
    codes:'',
    pwd:'',
  },
//获取验证码
  huoqu:function(){
    var phone = this.data.phone;
    var text = this.data.text;
    if(text=='30s'){
      if (!phone) {
        wx.showToast({
          title: '请输入手机号码',
          icon: 'none'
        })
        return;
      }
      var that = this;
      ea.qinqiu(that.data.getcode, { phone: phone }, function (data) {
        ea.TimeDown(30, function (number) {
          if(number==0){
            that.setData({ text: '30s' })
          }else{
            that.setData({ text: number + 's' })
          }
        })
      })
    }
  },
  //输入手机号码
  bindKeyInput1:function(e){
    var value = e.detail.value;
    this.setData({ phone: value});
    // console.log(value);
  },
  //输入验证码
  bindKeyInput:function(e){
    var value = e.detail.value;
    console.log(value);
    this.setData({codes:value});
  },
  //输入密码
  bindKeyInputs:function(e){
    var pwd = e.detail.value;
    this.setData({pwd:pwd});
  },
  //重置密码
  chongzhi:function(){
    var phone = this.data.phone;
    var code = this.data.codes;
    var pwd = this.data.pwd;
    var that = this;
    if(!phone){
      wx.showToast({
        title: '请输入手机号码',
        icon:'none'
      })
      return;
    }
    if (!code) {
      wx.showToast({
        title: '请输入验证码',
        icon: 'none'
      })
      return;
    }
    if (!pwd) {
      wx.showToast({
        title: '请输入密码',
        icon: 'none'
      })
      return;
    }
    ea.qinqiu(that.data.chengepwd,{phone:phone,code:code,pwd:pwd},function(data){
      console.log(data);
      wx.showToast({
        title: '修改成功',
      });
      setTimeout(function(){
        wx.navigateBack({
          delta:1
        })
      },1000)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})